class NumberContainers {
public:
    map<int, int> index2num;
    map<int, set<int>> num2indexs;
    NumberContainers() {
        
    }
    
    void change(int index, int number) { //修改或替换
        if(index2num[index]!=0) //原下标存在，则先修改
        {
            int oldnum=index2num[index];
            num2indexs[oldnum].erase(index);
        }
        index2num[index]=number;
        num2indexs[number].insert(index);

    }
    
    int find(int number) { //返回最小下标
        if(num2indexs[number].empty()) return -1; //如果不在
        return *num2indexs[number].begin();
    }
};

/**
 * Your NumberContainers object will be instantiated and called as such:
 * NumberContainers* obj = new NumberContainers();
 * obj->change(index,number);
 * int param_2 = obj->find(number);
 */